import { Group, Object3DEventMap, Scene } from "three";
import { ThreeScene } from "../three/scene";
import { ThreeLight } from "../three/light";
import { InsideMesh } from "../mesh/inside";
import { AnchorGltf } from "../gltf/anchor";
import { MurdererSprite } from "../sprite/murderer";
import { PointSprite } from "../sprite/point";


export class InsideScene {
    private threeScene = new ThreeScene();
    private threeLight = new ThreeLight();
    private insideMesh = new InsideMesh();
    private anchorGltf = new AnchorGltf();
    private pointSprite = new PointSprite();
    private murdererSprite = new MurdererSprite();

    private anchorMeshes: Group<Object3DEventMap>[] = [];
    private scene;

    constructor() {
        this.scene = this.threeScene.create();
    }

    create() {

        let light = this.threeLight.hemisphere();
        light.position.set(0, 40, 0);
        this.scene.add(light);

        let light2 = this.threeLight.directional();
        light2.position.set(0, 40, -10);
        this.scene.add(light2);

        const mesh = this.insideMesh.create();
        this.scene.add(mesh);

        const interactPoints = [
            { name: 'point_3_inside_eating_room', scale: 2, x: -30, y: 1, z: 20 },
            { name: 'point_4_inside_bed_room', scale: 3, x: 48, y: 0, z: -20 },
            { name: 'point_5_inside_back', scale: 3, x: 18, y: -13, z: 44 }
        ];

        const anchorP = this.anchorGltf.loader();
        this.anchorMeshes = []

        interactPoints.map(item => {
            let point = this.pointSprite.load(item);
            this.scene.add(point)
            anchorP.then(object => {
                let anchor = object.scene.clone();
                anchor.position.set(item.x, item.y + 3, item.z);
                anchor.name = item.name;
                anchor.scale.set(item.scale, item.scale, item.scale);
                this.anchorMeshes.push(anchor)
                this.scene.add(anchor);
            })
        })

        return this.scene;
    }

    addMurderer() {
        const murderer = this.murdererSprite.load()
        this.scene.add(murderer)
    }
}